<?php
if(!defined("IICCMS")) exit("Access Denied");
class UserAction extends BaseAction{
	private $uinfo=array();
	public function _initialize() {
		parent::_initialize();
		if(empty($_SESSION['uid'])||empty($_SESSION['uname'])){
			$this->assign ( 'jumpUrl', U('Login/index') );
			$this->error(L('no_login'));
		}else{
			$this->uinfo['uid']=$_SESSION ['uid'];
			$this->uinfo['uname']=$_SESSION ['uname'];
			$this->uinfo['is_ltd']=$_SESSION ['is_ltd'];
			$this->uinfo['rid']=$_SESSION ['rid'];
			$this->uinfo['tid']=$_SESSION ['tid'];
			$this->uinfo['email']=$_SESSION ['email'];
			$this->assign('uinfo',$this->uinfo);
		}
	}
	
	/**
	   *会员中心首页
	   *@date 2011-7-28
	   *@time 上午03:15:25
	   */
	function index() {
		//会员中心首页
		$condition=array();
		$condition['userid']=$this->uinfo['uid'];
		$gbk=M("Guestbook");
		$msg=array();
		$msg=$gbk->where($condition)->order('createtime DESC')->limit('0,5')->findAll();
		$this->assign("msg",$msg);
		$this->assign ('seo_title','商务中心--会员中心');
		$this->assign ('seo_keywords','汇景网,商务中心,会员中心');
		$this->assign ('seo_description','汇景网,商务中心,会员中心');
		$this->display();
	}//end index
	
	/**
	   *用户资料管理
	   *@date 2011-7-28
	   *@time 上午07:28:35
	   */
	function profile() {
		//用户资料管理
		//$this->display(THINK_PATH.'/Tpl/Autoindex/hello.html');
		$this->assign ('seo_title','商务中心--会员中心--个人资料修改');
		$this->assign ('seo_keywords','汇景网,商务中心,会员中心');
		$this->assign ('seo_description','汇景网,商务中心,会员中心');
		
		$member=D("Biz.Member");
		$condition=array();
		$condition['id']=$this->uinfo['uid'];
		$condition['username']=$this->uinfo['uname'];
		if ($_POST['act']=='update'){
			$password = trim ( $_POST ['password'] );
//			$verifyCode = trim ( $_POST ['verifyCode'] );
//			if (md5 ( $verifyCode ) != $_SESSION ['verify']) {
//				$this->error ( L ( 'error_verify' ) );
//			}
			$vo=array();
			if($_POST ['oldpassword']){
				$condition['password']=sysmd5($_POST ['oldpassword']);
				if($password!=$_POST['repassword']){
					$this->error ('两次密码不一致');
				}
				if(empty($_POST['email'])){
					$this->error ('邮箱地址必须填写');
				}
			}else{
				unset($_POST['oldpassword']);
				unset($_POST['password']);
				unset($_POST['repassword']);
			}
			$vo['tel']=$_POST['tel'];
			$vo['realname']=$_POST['realname'];
			$vo['sex']=$_POST['sex'];
			$vo['question']=$_POST['question'];
			$vo['answer']=$_POST['answer'];
			$vo['mobile']=$_POST['mobile'];
			$vo['about']=strip_tags(nl2br($_POST['about']),'<br>');
			if(false!==$member->where($condition)->save($vo)){	
				$this->success('修改成功！');
			}else{
				$this->error("更新失败");
			}
		}
		$info=array();
		$info=$member->where($condition)->find();
		$this->assign('info',$info);
		$this->display();
	}//end profile
	
	/**
	   *景区管理
	   *@date 2011-7-28
	   *@time 上午07:40:58
	   */
	function tour() {
		//景区管理
		if($this->uinfo['is_ltd']){
			if($this->uinfo['tid']){
				$this->tour_index();
			}else{
				
			}
		}else{
			$this->error("企业用户才能进行景区管理");			
		}
	}//end tour
	
	/**
	   *景区资料维护
	   *@date 2011-7-29
	   *@time 上午11:14:31
	   */
	function tour_index() {
		//景区资料维护
		$this->display();
	}//end tour_update
	
	/**
	   *申请景区资料维护
	   *@date 2011-7-29
	   *@time 上午11:21:23
	   */
	function tour_reg() {
		//申请景区资料维护
		;
	}//end tour_reg
	/**
	   *行业服务
	   *@date 2011-7-28
	   *@time 上午07:41:25
	   */
	function server() {
		//行业服务
	}//end server
	
	/**
	   *需求信息
	   *@date 2011-7-28
	   *@time 上午07:41:48
	   */
	function info() {
		//需求信息
		$this->assign ('seo_title','商务中心--会员中心--需求信息');
		$this->assign ('seo_keywords','汇景网,商务中心,会员中心');
		$this->assign ('seo_description','汇景网,商务中心,会员中心');
		$dao=M("Info");
		$condition=array();
		$condition['tid']=$this->uinfo['tid'];
		$condition['userid']=$this->uinfo['uid'];
		//$condition['status']='1';
		$list=array();
		import("@.ORG.ZQPage");
		$count=$dao->where($condition)->count();
		$page = new ZQPage($count,25,6);
		$pages = $page->show();
		$list=$dao->where($condition)->order('id desc')->limit($page->firstRow.",25")->select();
		$this->assign("list",$list);
		$this->assign('pages',$pages);
		$this->display();
	}//end info
	
	function info_add() {
		$dao=M("Info");
		if($_REQUEST['act']=='edit'){
			$id=intval($_GET['id']);
			if(empty($id)){
				$this->error("参数错误");
			}
			$endtime=time()-60*60*24*30;//一个月前
			$confition=array();
			$confition['updatetime']=array('gt',$endtime);
			$confition['userid']=array('eq',$this->uinfo['uid']);
			$confition['id']=array('eq',$id);
			$vo=$dao->where($confition)->find();
			if(empty($vo)){
				$this->error("权限不够或参数错误");
			}else{
				$this->assign('info',$vo);
			}
		}
		if($_REQUEST['act']=='update'){
			if($_POST['id']){//更新
				$id=intval($_GET['id']);
				$vo=$dao->create();
				if(empty($vo)){
					$this->error($dao->getError());
				}else{
					$vo['content']=nl2br($vo['content']);
					$vo['content']=strip_tags($vo['content'],'<br>');
					$vo['updatetime']=time();
					$dao->save($vo);
				}
			}else{//新加
				$vo=$dao->create();
				if(empty($vo)){
					$this->error($dao->getError());
				}else{
					$vo['content']=nl2br($vo['content']);
					$vo['content']=strip_tags($vo['content'],'<br>');
					$vo['userid']=$this->uinfo['uid'];
					$vo['username']=$this->uinfo['uname'];
					$vo['tid']=empty($this->uinfo['tid'])?'0':$this->uinfo['tid'];
					$vo['catid']=6;
					$vo['createtime']=time();
					$vo['endtime']=time()+(60*60*24*7);
					$id=$dao->add($vo);
					if($id){
						$this->assign ( 'jumpUrl', U('User/index') );
						$this->success (L('add_ok'));
					}else{
						$this->error($dao->getError());
					}
				}
			}
		}//写入操作
		$this->display ();
	}
	/**
	   *招聘管理
	   *@date 2011-7-28
	   *@time 上午07:42:10
	   */
	function job() {
		//招聘管理
		$this->display(THINK_PATH.'/Tpl/Autoindex/hello.html');
	}//end job
	
	/**
	   *留言管理
	   *@date 2011-7-28
	   *@time 上午07:42:28
	   */
	function msg() {
		//留言管理
		$act=$_POST['act'];
		$dao=M('Guestbook');
		if($act=='add'){
			$vo=array();
			$vo['title']=$_POST['title'];
			$vo['content']=nl2br($_POST['title']);
			$vo['content']=strip_tags($vo['content'],'<br>');
			$vo['userid']=$this->uinfo['uid'];
			$vo['username']=$this->uinfo['uname'];
			$vo['createtime']=time();
			$vo['ip']=get_client_ip();
			$id=$dao->add($vo);
			if ($id){
				$this->assign ( 'jumpUrl', U('User/index') );
				$this->success (L('add_ok'));
			}else{
				$this->error($dao->getError());
			}
		}else{
			$condition=array();
			$condition['userid']=$this->uinfo['uid'];
			$list=array();
			import("@.ORG.ZQPage");
			$count=$dao->where($condition)->count();
			$listRows=C('PAGE_LISTROWS');
			$page = new ZQPage($count,$listRows,6);
			$pages = $page->show();
			$list=$dao->where($condition)->order('id desc')->limit($page->firstRow.",$listRows")->select();
			$this->assign("list",$list);
			$this->assign('pages',$pages);
		}
		$this->display();
	}//end msg
	
	/**
	   *个人简历
	   *@date 2011-7-28
	   *@time 上午07:43:13
	   */
	function about() {
		//个人简历
		$this->display(THINK_PATH.'/Tpl/Autoindex/hello.html');
	}//end about
}